<template>
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="dialogVisible" class="re-dialog" width="1050px">
        
        <div class="copy-row">
            <button @click = "copyRight">复制</button>
        </div>

        <el-row v-if="handleType === 'workbench'" class="row" v-for="(item,index) in defaultShowList" :key="index">
            <el-col v-for="(sItem,sIndex) in item" :key="sIndex" :span="12">
                <label class="el-label" for="">{{sItem.label}}：</label>
                <span>{{sItem.value}}</span>
            </el-col>
        </el-row>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="170px">
            <el-row>
                <el-col :span="12">
                    <el-form-item label="操作：" prop="status">
                        <el-radio-group v-model="ruleForm.status">
                            <el-radio v-for="(item,index) in statusList" :key="index" class="radio-li" v-bind:label="item.value">{{item.label}}</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
                <el-col v-if="ruleForm.status == '1'" :span="12">
                    <el-form-item label="驳回原因：" prop="opinion">
                        <el-select class="w-100" v-model="ruleForm.opinion" placeholder = "请选择驳回原因">
                            <el-option 
                                v-for="(item,index) in opinionList"
                                :key = "index"
                                :label = "item.dictDataName"
                                :value = "item.dictDataName"
                                 ></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row v-for="(item,index) in formConfig" :key="index">
                <el-col v-for="(sItem,sIndex) in item" :key="sIndex" :span="12">
                    <el-form-item v-if="sItem.type !== 'rangeDatePicker'" :error="sItem.tips" v-bind:label="sItem.label" v-bind:prop="sItem.code">
                        <el-input @blur="onInputBlur(sItem)" v-bind:maxlength="sItem.maxlength" v-if="sItem.type === 'input'" v-bind:placeholder="sItem.placeholder" v-model="ruleForm[sItem.code]"></el-input>
                        <el-input v-bind:maxlength="sItem.maxlength" v-else-if="sItem.type === 'numberInput'" v-bind:placeholder="sItem.placeholder" v-model.number="ruleForm[sItem.code]"></el-input>
                        <el-select class="w-100" v-else-if="sItem.type === 'select'" v-model="ruleForm[sItem.code]" v-bind:placeholder="sItem.placeholder">
                            <el-option v-for="(ssItem,ssIndex) in sItem.data" :key="ssIndex" v-bind:label="ssItem.label" v-bind:value="ssItem.value"></el-option>
                        </el-select>
                        <div v-else-if="sItem.type === 'rangeDatePicker'" class="flex">
                            <el-date-picker placeholder="开始日期" v-model="ruleForm[sItem.code]" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date" style="width: 145px;"></el-date-picker>
                            <span class="date-t">至</span>
                            <el-date-picker placeholder="结束日期" v-model="ruleForm[sItem.code]" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date" style="width: 145px;"></el-date-picker>
                        </div>

                        <Upload v-on:onSuccess="onUploadSuccess" :defaultUrl="ruleForm[sItem.code]" :item="sItem" v-else-if="sItem.type === 'upload'" />
                        <el-radio-group v-else-if="sItem.type === 'radio'" v-model="ruleForm[sItem.code]">
                            <el-radio v-for="(ssItem,ssIndex) in sItem.data" :key="ssIndex" class="radio-li" v-bind:label="ssItem.value">{{ssItem.label}}</el-radio>
                        </el-radio-group>
                        <SelectWindow :disabled="disabledWindow" :value="ruleForm[sItem.code]" v-on:onSelect="onSelectWindow" v-else-if="sItem.type==='selectWindow'" />
                    </el-form-item>
                    <el-form-item v-if="sItem.type === 'rangeDatePicker'" :required="sItem.required" v-bind:label="sItem.label">
                        <div class="flex">
                            <el-form-item v-bind:prop="sItem.date1">
                                <el-date-picker placeholder="开始日期" v-model="ruleForm[sItem.date1]" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date" style="width: 145px;"></el-date-picker>
                            </el-form-item>
                            <span class="date-t">至</span>
                            <el-form-item v-bind:prop="sItem.date2">
                                <el-date-picker placeholder="结束日期" v-model="ruleForm[sItem.date2]" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date" style="width: 145px;"></el-date-picker>
                            </el-form-item>

                        </div>
                    </el-form-item>
                </el-col>
            </el-row>
             <el-row>
                <el-col :span="12">
                    <el-form-item label="取件方式：" prop="getType">
                        <el-radio-group v-model="ruleForm.getType">
                            <el-radio v-for="(item,index) in getTypeList" :key="index" class="radio-li" v-bind:label="item.value">{{item.label}}</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
                <el-col v-if="ruleForm.getType == '0'" :span="12">
                    <el-form-item label="邮寄地址：" prop="applyPersonAddress">
                        <el-input maxlength="300" v-model="ruleForm.applyPersonAddress" placeholder="请输入邮寄地址"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
             <el-row>
                <el-col :span="24">
                    <el-form-item label="备注：" prop="remark">
                        <el-input type = "textarea" maxlength="300" v-model="ruleForm.remark" placeholder="请输入备注"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <button class="footer-btn cancel" @click="dialogVisible = false">取 消</button>
            <button @click="onSubmit('ruleForm')" class="footer-btn sure">确定</button>
        </span>
    </el-dialog>
</template>

<script>
import { chunkArr, getCookie, invalid, getTimeStr } from "../../utils";
import {
    findByDictCode,
    tyAddHandle,
    findByCredentialNum
} from "../../config/api";
import SelectWindow from "../common/selectWindow.vue";
import Upload from "../common/upload.vue";
import { Message } from "element-ui";
import Pubsub from "../../utils/pubsub";
let defaultShowConfig = [
    { label: "取号码", value: "", code: "rankNum" },
    { label: "取号时间", value: "", code: "takeTime" }
    // { label: "办理事项", value: "", code: "handleInfoName" }
];
let defaultFormConfig = {
    handleInfo: {
        label: "办理事项：",
        value: "",
        code: "handleInfo",
        type: "select",
        placeholder: "选择办理事项",
        data: []
    },
    areaCode: {
        label: "区域：",
        value: "",
        code: "areaCode",
        type: "select",
        placeholder: "请选择区域",
        data: []
    },
    handlePersonTelNo: {
        label: "经办人联系方式：",
        value: "",
        code: "handlePersonTelNo",
        type: "numberInput",
        placeholder: "请输入经办人联系方式",
        maxlength: 11
    },
    windowNum: {
        label: "事项归属窗口：",
        value: "",
        code: "windowNum",
        type: "selectWindow",
        placeholder: "请选择事项归属窗口"
    },
    handlePersonCardNum: {
        label: "经办人证件号码：",
        value: "",
        code: "handlePersonCardNum",
        type: "input",
        upFileId: "handlePersonFileId",
        cardId: "handlePersonCardId",
        path: "handlePersonFilePath",
        cType: "handlePersonCardType",
        owner: "handlePersonName",
        startTime: "handlePersonStartTime",
        endTime: "handlePersonEndTime",
        placeholder: "请输入经办人证件号码",
        maxlength: 32
    },
    applyPersonCardNum: {
        label: "申请单位/人证件号码：",
        value: "",
        code: "applyPersonCardNum",
        type: "input",
        upFileId: "applyPersonFileId",
        cardId: "applyPersonCardId",
        cType: "applyPersonCardType",
        owner: "applyPersonName",
        path: "applyPersonFilePath",
        startTime: "applyPersonStartTime",
        endTime: "applyPersonEndTime",
        placeholder: "请输入申请单位/人证件号码",
        maxlength: 32
    },
    handlePersonName: {
        label: "经办人姓名：",
        value: "",
        code: "handlePersonName",
        type: "input",
        placeholder: "请输入经办人姓名",
        maxlength: 5
    },
    applyPersonName: {
        label: "申请单位/人名称：",
        value: "",
        code: "applyPersonName",
        type: "input",
        placeholder: "请输入申请单位/人名称",
        maxlength: 64
    },

    handlePersonCardType: {
        label: "经办人证件类型：",
        value: "",
        code: "handlePersonCardType",
        type: "select",
        placeholder: "请选择经办人证件类型",
        data: []
    },
    applyPersonCardType: {
        label: "申请单位/人证件类型：",
        value: "",
        code: "applyPersonCardType",
        type: "select",
        placeholder: "请选择申请单位/人证件类型",
        data: []
    },

    handlePersonTime: {
        label: "经办人证件有效期：",
        value: "",
        code: "handlePersonTime",
        type: "rangeDatePicker",
        date1: "handlePersonStartTime",
        date2: "handlePersonEndTime",
        placeholder: "请输入经办人证件有效期"
    },
    applyPersonTime: {
        label: "申请单位/人证件有效期：",
        value: "",
        code: "applyPersonTime",
        type: "rangeDatePicker",
        required: true,
        date1: "applyPersonStartTime",
        date2: "applyPersonEndTime",
        placeholder: "请输入申请单位/人证件有效期"
    },
    handlePersonFilePath: {
        label: "经办人证件：",
        value: "",
        code: "handlePersonFilePath",
        upFileId: "handlePersonFileId",
        cardId: "handlePersonCardId",

        type: "upload",
        url: ""
    },
    applyPersonFilePath: {
        label: "申请单位/人证件：",
        value: "",
        code: "applyPersonFilePath",
        upFileId: "applyPersonFileId",
        cardId: "applyPersonCardId",
        type: "upload",
        url: ""
    },
    // status: {
    //     label: "操作：",
    //     value: "",
    //     code: "status",
    //     type: "radio",
    //     data: [{ label: "接件", value: "0" }, { label: "驳回", value: "1" }]
    // },
    // getType: {
    //     label: "取件方式：",
    //     value: "",
    //     code: "getType",
    //     type: "radio",
    //     data: [
    //         { label: "到付邮寄", value: "0" },
    //         { label: "现场取件", value: "1" }
    //     ]
    // },
    // applyPersonAddress: {
    //     label: "邮寄地址：",
    //     value: "",
    //     code: "applyPersonAddress",
    //     type: "input",
    //     placeholder: "请输入邮寄地址",
    //     maxlength: 128
    // }
};
let token = getCookie("token");
let validatorPhone = (rule, value, callback) => {
    if (value && !invalid.mobileReg.test(value)) {
        callback(new Error("请输入正确的11位手机号码"));
    } else {
        callback();
    }
};

export default {
    components: {
        SelectWindow,
        Upload
    },
    props: ["title", "disabledWindow"],
    data() {
        let validatorHandlerCode = (rule, value, callback) => {
            let { handlePersonCardType } = this.ruleForm;
            if (value && !handlePersonCardType) {
                this.$refs.ruleForm.validateField(["handlePersonCardType"]);
                callback();
            } else if (!value && handlePersonCardType) {
                callback(new Error("请输入经办人证件号码"));
            } else {
                callback();
            }
        };
        let validatorHandlerType = (rule, value, callback) => {
            let { handlePersonCardNum } = this.ruleForm;
            if (value && !handlePersonCardNum) {
                this.$refs.ruleForm.validateField(["handlePersonCardNum"]);
                callback();
            } else if (!value && handlePersonCardNum) {
                callback(new Error("请选择经办人证件类型"));
            } else {
                callback();
            }
        };
        let validHandlePersonStartTime = (rule, value, callback) => {
            let { handlePersonEndTime } = this.ruleForm;
            if (value && !handlePersonEndTime) {
                this.$refs.ruleForm.validateField(["handlePersonEndTime"]);
                callback();
            } else if (!value && handlePersonEndTime) {
                callback(new Error("请选择开始日期"));
            } else if (getTime(value) > getTime(handlePersonEndTime)) {
                this.$refs["ruleForm"].clearValidate(["handlePersonStartTime"]);
                callback(new Error("开始日期不能大于结束日期"));
            } else {
                callback();
            }
        };
        let validHandlePersonEndTime = (rule, value, callback) => {
            let { handlePersonStartTime } = this.ruleForm;
            if (value && !handlePersonStartTime) {
                this.$refs.ruleForm.validateField(["handlePersonStartTime"]);
                callback();
            } 
            // else if (!value && handlePersonStartTime) {
            //     callback(new Error("请选择结束日期"));
            // } 
            else if (value && (getTime(value) < getTime(handlePersonStartTime))) {
                this.$refs["ruleForm"].clearValidate(["handlePersonEndTime"]);
                callback(new Error("结束日期不能小于开始日期"));
            } else {
                callback();
            }
        };
        let validApplyPersonStartTime = (rule, value, callback) => {
            let isInvalid = this.rules["applyPersonStartTime"][0].required;//是否需要验证
            let { applyPersonEndTime } = this.ruleForm;
            if (value && !applyPersonEndTime) {
                this.$refs.ruleForm.validateField(["applyPersonEndTime"]);
                callback();
            } else if (!value && isInvalid) {
                callback(new Error("请选择开始日期"));
            } else if (getTime(value) > getTime(applyPersonEndTime)) {
                this.$refs["ruleForm"].clearValidate(["applyPersonStartTime"]);
                callback(new Error("开始日期不能大于结束日期"));
            } else {
                this.$refs.ruleForm.validateField(["applyPersonEndTime"]);
                callback();
            }
        };
        let validApplyPersonEndTime = (rule, value, callback) => {
            let { applyPersonStartTime } = this.ruleForm;
              let isInvalid = this.rules["applyPersonEndTime"][0].required;//是否需要验证
            if (value && !applyPersonStartTime) {
                this.$refs.ruleForm.validateField(["applyPersonStartTime"]);
                callback();
            }
            //  else if (!value && isInvalid) {
            //     callback(new Error("请选择结束日期"));
            // } 
            else if (value && (getTime(value) < getTime(applyPersonStartTime))) {
                this.$refs["ruleForm"].clearValidate(["applyPersonEndTime"]);
                callback(new Error("结束日期不能小于开始日期"));
            } else {
                callback();
            }
        };
        /**
         * 获取时间戳
         */
        let getTime = tamp => {
            return new Date(tamp).getTime();
        };
        return {
            dialogVisible: false,
            defaultShowList: [],
            formConfig: [],
            opinionList:[],//驳回原因下拉列表
            statusList: [
                { label: "接件", value: "0" },
                { label: "驳回", value: "1" }
            ], //操作列表
            getTypeList:[//取件方式
                { label: "到付邮寄", value: "0" },
                { label: "现场取件", value: "1" }
            ],
            ruleForm: {
                handleInfo: "",
                handlePersonName: "", //经办人姓名
                applyPersonName: "", //申请人
                handlePersonTelNo: "", //经办人联系方式
                applyPersonAddress: "", //邮寄地址
                handlePersonCardType: "1", //经办人证件类型
                handlePersonCardNum: "", //经办人证件号码
                applyPersonCardType: "", //申请人证件类型
                applyPersonCardNum: "", //申请人证件号码
                handlePersonTime: "", //经办人证件有效期
                handlePersonStartTime: "", //经办人证件有效期
                applyPersonTime: "", //申请证件有效期
                applyPersonStartTime: "", //申请证件有效期
                handlePersonFileId: "", //经办人证件
                handlePersonFilePath: "", //经办人证件url
                applyPersonFileId: "", //申请人证件
                applyPersonFilePath: "", //申请人证件url
                status: "0", //操作，默认接受
                windowNum: "", //归属窗口
                getType: "0", //取件方式
                opinion: "", //驳回原因
                areaCode: "", //区域编码
                remark: "", //备注
            },
             rules: {
                handleInfo: [
                    {
                        required: true,
                        message: "请选择办理事项",
                        trigger: "change"
                    }
                ],
                windowNum: [
                    {
                        required: true,
                        message: "请选择事项归属窗口",
                        // trigger: "change"
                    }
                ],
                areaCode: [
                    {
                        required: true,
                        message: "请选择区域",
                        trigger: "change"
                    }
                ],
                handlePersonName: [
                    {
                        required: true,
                        message: "请输入经办人姓名",
                        trigger: "blur"
                    }
                ],
                applyPersonName: [
                    {
                        required: true,
                        message: "请输入申请单位/人姓名",
                        trigger: "blur"
                    }
                ],
                handlePersonTelNo: [
                    {
                        // required: true,
                        trigger: "blur",
                        validator: validatorPhone
                    },
                    // {
                    //     required: true,
                    //     trigger: "blur",
                    //     message: "请输入经办人联系方式"
                    // }
                ],
                applyPersonAddress: [
                    {
                        required: true,
                        message: "请输入邮寄地址",
                        trigger: "blur"
                    }
                ],
                handlePersonCardType: [
                    {
                        // required: true,
                        // message: "请选择经办人证件类型",
                        trigger: "change",
                        validator: validatorHandlerType
                    }
                ],
                applyPersonCardType: [
                    {
                        required: true,
                        message: "请选择申请单位/人证件类型",
                        trigger: "change"
                    }
                ],

                handlePersonCardNum: [
                    {
                        required: true,
                        message: "请输入经办人证件号码",
                        trigger: "blur",
                        validator: validatorHandlerCode
                    }
                ],

                applyPersonCardNum: [
                    {
                        required: true,
                        message: "请输入申请单位/人证件号码",
                        trigger: "blur"
                    }
                ],

                // handlePersonTime: [
                //     {
                //         // required: true,
                //         // message: "请选择经办人证件有效期",
                //         // trigger: "change"
                //     }
                // ],

                applyPersonTime: [
                    {
                        required: true,
                        message: "请选择申请单位/人证件有效期",
                        trigger: "change"
                    }
                ],
                handlePersonFilePath: [
                    {
                        // required: true,
                        // message: "请上传经办人证件",
                        // trigger: "change"
                    }
                ],
                applyPersonFilePath: [
                    {
                        required: true,
                        message: "请上传申请单位/人证件",
                        trigger: "change"
                    }
                ],
                status: [{ required: true }],

                getType: [
                    {
                        required: true,
                        message: "请选择取件方式",
                        trigger: "change"
                    }
                ],
                opinion: [
                    {
                        required: true,
                        message: "请输入驳回原因",
                        trigger: "change"
                    }
                ],
                handlePersonStartTime: [
                    {
                        trigger: "change",
                        validator: validHandlePersonStartTime
                    }
                ],
                handlePersonEndTime: [
                    {
                        trigger: "change",
                        validator: validHandlePersonEndTime
                    }
                ],
                applyPersonStartTime: [
                    {
                        required: true,
                        message:"请选择开始日期",
                        trigger: "change",
                        type: "date",
                        validator: validApplyPersonStartTime
                    }
                ],
                applyPersonEndTime: [
                    {
                        // required: true,
                        // message:"请选择结束日期",
                        trigger: "change",
                        type: "date",
                        validator: validApplyPersonEndTime
                    }
                ]
            }
        };
    },
    created() {
        this.handleDefaultForm(); //处理form表单
        this.getDic("areaCode","areaCode"); //获取区域code
        this.getDic("handleInfo","handleInfo"); //获取办理事项
        this.getDic("cardType","handlePersonCardType","applyPersonCardType"); //获取证件类型数据字典
        this.setPubsub();
        this.getOpinionList();
    },
    
    destroyed() {
        this.pubsub_token1 && Pubsub.unsubscribe(this.pubsub_token1);
        this.pubsub_token2 && Pubsub.unsubscribe(this.pubsub_token2);
        this.pubsub_token3 && Pubsub.unsubscribe(this.pubsub_token3);
    },
    methods: {
        /**
         * 获取驳回原因列表
         */
        getOpinionList(){
            findByDictCode({dictCode:"backReason"}).then((result = {})=>{
                let data = result.data || [];
                this.opinionList = data;
            })
        },
        /**
         * 将经办人信息复制到申请人
         */
        copyRight(){
            let {
                handlePersonCardType,handlePersonName,
                handlePersonCardNum,handlePersonStartTime,
                handlePersonEndTime,handlePersonFileId,
                handlePersonFilePath,handlePersonTime,handlePersonCardId
            } = this.ruleForm;
            this.ruleForm.applyPersonName = handlePersonName;
            this.ruleForm.applyPersonCardNum = handlePersonCardNum;
            this.ruleForm.applyPersonCardId = handlePersonCardId;
            this.ruleForm.applyPersonCardType = handlePersonCardType;
            this.ruleForm.applyPersonTime = handlePersonTime;
            this.ruleForm.applyPersonStartTime = handlePersonStartTime;
            this.ruleForm.applyPersonEndTime = handlePersonEndTime;
            this.ruleForm.applyPersonFileId = handlePersonFileId;
            this.ruleForm.applyPersonFilePath = handlePersonFilePath;
        },
        setPubsub(){
            this.pubsub_token1 = Pubsub.subscribe(
                "showRegisterDialog",
                (p, arg = {}) => {
                    this.handleDetailData(arg);
                    this.dialogVisible = true;
                    let {handleType,type} = arg;
                    this.handleType = handleType;
                    if(type == "ywsl"){//业务受理过来的
                        let windowNum = getCookie("windowNum");
                        this.ruleForm.windowNum = windowNum;
                    }
                    if(handleType == "workbench"){//工作台弹窗。
                        this.handleDefaultConfig(arg);
                        if(arg.handlePersonCardNum){//工作台弹窗需要请求回填证件照
                            this.onInputBlur({
                                label: "经办人证件号码：",
                                value: "",
                                code: "handlePersonCardNum",
                                type: "input",
                                upFileId: "handlePersonFileId",
                                cardId: "handlePersonCardId",
                                path: "handlePersonFilePath",
                                cType: "handlePersonCardType",
                                startTime: "handlePersonStartTime",
                                endTime: "handlePersonEndTime",
                                placeholder: "请输入经办人证件号码",
                                maxlength: 32
                            })
                        }
                        console.log(arg,"woek")
                    }
                    setTimeout(() => {
                        this.$refs.ruleForm.clearValidate();
                    }, 0);
                }
            );
            this.pubsub_token2 = Pubsub.subscribe(
                "hideRegisterDialog",
                (p, arg = {}) => {
                    this.dialogVisible = false;
                }
            );
            this.pubsub_token3 = Pubsub.subscribe(//装填数据（因为详情数据需要请求接口）。
                "refreshDialogData",
                (p, arg = {}) => {
                    this.handleDetailData(arg);
                }
            );
        },
        handleDetailData(arg){
            let {
                    handlePersonStartTime,
                    handlePersonEndTime,
                    applyPersonStartTime,
                    applyPersonEndTime,
                } = arg;
                // if(handleType){//列表新增
                // }
                // if(type == "ywsl"){
                //     defaultFormConfig[0] = defaultFormConfig[1];
                //     defaultFormConfig[1] = {};
                //     this.handleFormConfig(defaultFormConfig);
                // }
                this.ruleForm = {
                        handlePersonName: "", //经办人姓名
                        handleInfo: "", //办理事项
                        applyPersonName: "", //申请人
                        handlePersonTelNo: "", //经办人联系方式
                        applyPersonAddress: "", //邮寄地址
                        handlePersonCardType: "1", //经办人证件类型
                        handlePersonCardNum: "", //经办人证件号码
                        applyPersonCardType: "", //申请人证件类型
                        applyPersonCardNum: "", //申请人证件号码
                        handlePersonTime: "", //经办人证件有效期
                        handlePersonStartTime: "", //经办人证件有效期
                        handlePersonEndTime: "", //经办人证件有效期
                        applyPersonTime: "", //申请证件有效期
                        applyPersonStartTime: "", //申请证件有效期
                        applyPersonEndTime: "", //申请证件有效期
                        handlePersonFileId: "", //经办人证件
                        handlePersonFilePath: "", //经办人证件url
                        applyPersonFileId: "", //申请人证件
                        applyPersonFilePath: "", //申请人证件url
                        status: "0", //操作，默认接受
                        windowNum: "", //归属窗口
                        getType: "0", //取件方式
                        opinion: "", //驳回原因
                        remark: "", //备注
                        areaCode: "" //区域编码
                    };
                if (arg.handlePersonName) {
                    this.ruleForm = Object.assign(this.ruleForm,arg);
                    if (handlePersonStartTime) {
                        this.ruleForm.handlePersonStartTime = getTimeStr(
                            handlePersonStartTime,
                            "yyyy-MM-dd"
                        );
                        this.ruleForm.handlePersonEndTime = getTimeStr(
                            handlePersonEndTime,
                            "yyyy-MM-dd"
                        );
                    }
                    if (applyPersonStartTime) {
                        this.ruleForm.applyPersonStartTime = getTimeStr(
                            applyPersonStartTime,
                            "yyyy-MM-dd"
                        );
                        this.ruleForm.applyPersonEndTime = getTimeStr(
                            applyPersonEndTime,
                            "yyyy-MM-dd"
                        );
                    }
                } else {
                    
                }
        },
          //处理默认配置
        handleDefaultConfig(defaultInfo = {}) {
            defaultInfo.takeTime = getTimeStr(defaultInfo.takeTime);
            defaultShowConfig.map(item => {
                item.value = defaultInfo[item.code];
            });
            this.ruleForm.handleInfo = defaultInfo.handleInfo;
            this.ruleForm.handleInfoName = defaultInfo.handleInfoName;
            this.ruleForm.takeNumId = defaultInfo.id;
            this.ruleForm.handlePersonName = defaultInfo.handlePersonName;
            this.ruleForm.handlePersonCardNum = defaultInfo.handlePersonCardNum;
            this.ruleForm.handlePersonTelNo = defaultInfo.telNo;
            this.ruleForm.handlePersonCardType = "1";
            this.ruleForm.status = "0";
            let arr = chunkArr(defaultShowConfig, 2);
            // let formArr = chunkArr(defaultFormConfig, 2);
            this.defaultShowList = arr;
            // this.formConfig = formArr;
        },
        handleDefaultForm() {
            let newForm = [];
            for (let i in defaultFormConfig) {
                newForm.push(defaultFormConfig[i]);
            }
            let formArr = chunkArr(newForm, 2);
            this.formConfig = formArr;
        },
        //获取数据字典
        getDic(type,code,code1) {
            findByDictCode({ dictCode: type }).then((result = {}) => {
                let data = result.data || [];
                let arr = [];
                data.map(item => {
                    arr.push({
                        label: item.dictDataName,
                        value: item.dictDataCode
                    });
                });
                defaultFormConfig[code].data = arr;
                if(code1){
                    defaultFormConfig[code1].data = arr;
                }
                this.handleDefaultForm();
            });
        },
          /**
         * onSubmit提交
         */
        onSubmit(formName) {
            // this.$refs.ruleForm.validateField(["applyPersonStartTime"]);
            this.$refs[formName].validate(valid => {
                if (valid) {
                    this.$emit("onSubmit", this.ruleForm);
                } else {
                    console.log("error submit!!");
                    return false;
                }
            });
        },
        /**
         * 上传成功回调
         */
        onUploadSuccess(e) {
            this.ruleForm[e.code] = e.uploadPath;
            this.ruleForm[e.upFileId] = e.fileId;
            this.ruleForm[e.cardId] = "";
            this.ruleForm.applyPersonCardId = "";
            this.$refs.ruleForm.validateField(e.code);
        },
        /**
         * 选择窗口回调
         */
        onSelectWindow(num) {
            this.ruleForm.windowNum = num;
            this.$refs.ruleForm.validateField(["windowNum"]);
        },
        //input 失焦事件
        onInputBlur(item) {
            if (item.upFileId) {
                //证件号，需要请求证件库
                let type = this.ruleForm[item.cType];
                let credentialNum = this.ruleForm[item.code];
                findByCredentialNum({ credentialNum, type }).then(
                    (result = {}) => {
                        let data = result.data || {};
                        let url = data.filePath || "";
                        let startTime = data.startTime || "";
                        let endTime = data.endTime || "";
                        // if (item.code === "handlePersonCardNum") {
                        //     //经办人
                        //     defaultFormConfig[12].url = url;
                        // } else {
                        //     defaultFormConfig[13].url = url;
                        // }
                        if(startTime){
                            this.ruleForm[item.startTime] = getTimeStr(startTime,"yyyy-MM-dd");
                            this.ruleForm[item.endTime] = getTimeStr(endTime,"yyyy-MM-dd");
                        }
                        if (url) {
                            this.ruleForm[item.upFileId] = data.fileId || "";
                            this.ruleForm[item.path] = data.filePath || "";
                            this.ruleForm[item.cardId] = data.id || "";
                            this.ruleForm[item.owner] = data.owner || "";
                            this.ruleForm[item.cType] = data.cardType || "";
                            this.$refs.ruleForm.validateField(item.code);

                            // this.handleFormConfig(defaultFormConfig);
                        }
                    }
                );
            }
        },
        handleRulesRequired(code = [],type = false){//处理驳回操作时，部分字段非必填。
            code.map((item)=>{
                this.rules[item][0].required = type;
            })
        }
    },
    watch: {
        "ruleForm.status": {
            // deep: true,
            handler: function(n) {
                let requiredList = [
                        "areaCode","windowNum","applyPersonName","applyPersonCardNum","applyPersonCardType",
                        "applyPersonTime","applyPersonAddress","applyPersonFilePath","applyPersonStartTime","applyPersonEndTime",
                        ];
                this.handleRulesRequired(requiredList,n=='0');
                if(n == '1'){
                    defaultFormConfig["applyPersonTime"].required = false;
                }else{
                    defaultFormConfig["applyPersonTime"].required = true;
                }
                this.$refs.ruleForm.clearValidate();
                // if(n == '1'){
                //     let requiredList = [
                //         "areaCode","windowNum","applyPersonName","applyPersonCardNum","applyPersonCardType",
                //         "applyPersonTime","applyPersonAddress","applyPersonFilePath","applyPersonStartTime","applyPersonEndTime",
                //         ];
                //     this.handleRulesRequired(requiredList,false);
                // }else{
                //     let requiredList = [
                //         "areaCode","windowNum","applyPersonName","applyPersonCardNum","applyPersonCardType",
                //         "applyPersonTime","applyPersonAddress","applyPersonFilePath","applyPersonStartTime","applyPersonEndTime",
                //         ];
                //     this.handleRulesRequired(requiredList,true);
                // }
            }
        }
    }
};
</script>

<style lang = "scss" scoped>
.el-label {
    display: inline-block;
    width: 170px;
    text-align: right;
    padding-right: 12px;
    box-sizing: border-box;
}
.w-100 {
    width: 100%;
}
.row {
    margin-bottom: 15px;
    font-size: 12px;
}

.footer-btn {
    width: 66px;
    height: 32px;
    border-radius: 3px;
    &:active {
        opacity: 0.8;
    }
}
.date-t {
    margin: 0 10px;
    line-height: 32px;
}
.sure {
    background-color: #1a36a9;
    color: #fff;
}
.cancel {
    background-color: #d2d2d2;
    margin-right: 40px;
}
.copy-row{
    display: flex;
    justify-content: flex-end;
    button{
        color:#1d3aa6;
    }
}
</style>
<style>
.radio-li span {
    font-size: 12px !important;
    color: #606266;
}
</style>
